package com.webreport.webapp.bean;

import java.io.Serializable;

public class PaginationFilter implements Serializable {
	private static final long serialVersionUID = -5486374877706839553L;
	private int rowsPerPage =5;
	protected long count = 0;
	private int currentPage = 1;
	public PaginationFilter() {
	}
	
	public void setCount(long count) {
		this.count = count;
	}
	
	public long getCount() {
		return count;
	}
	
	public int getRowsPerPage() {
		return rowsPerPage;
	}

	public void setRowsPerPage(int rowsPerPage) {
		this.rowsPerPage = rowsPerPage;
	}

	public int getTotalPage() {
		int totalPage = 0;
		if (rowsPerPage != 0) {
			int i = 0;
			if ((getCount() % rowsPerPage) != 0) {
				i = 1;
			}
			totalPage = (int) ((getCount() / rowsPerPage) + i);
		}
		return totalPage;
	}
	
	public int getCurrentPage() {
		if (currentPage > this.getTotalPage())
			currentPage = this.getTotalPage();
		if (currentPage <= 0)
			currentPage = 1;
		return currentPage;
	}
	
	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}
	
	public int getCurrentStartRow() {
		int row = ((getCurrentPage() - 1) * rowsPerPage);
		if (row > getCount())
			row = (int)getCount();
		return row;
	}
	
	public int getCurrentEndRow() {
		int row = getCurrentPage() * rowsPerPage;
		if (row > getCount())
			row = (int)getCount();
		return row;
	}
}
